#include "log.h"

#include <strsafe.h>
#include <tchar.h>

#include "string.h"

using namespace windows::kernal;

NTSTATUS Log::Output(ULONG level, LPCSTR tag, LPCSTR path, ULONG line, LPCSTR format, ...) {
  for (SIZE_T i = _tcslen(path); 0 < i; --i) {
    if ('\\' == path[i - 1]) {
      NTSTATUS status;
#define MAX_PREFIX_LENGTH 0x100
      CHAR prefix_buffer[MAX_PREFIX_LENGTH] = {0};
      StringCbPrintfA(prefix_buffer, _ARRAYSIZE(prefix_buffer), "[%s] %s:%d ", tag, &path[i], line);

      va_list list;
      va_start(list, format);
      status = vDbgPrintExWithPrefix(prefix_buffer, DPFLTR_IHVDRIVER_ID, level, format, list);
      //NTSTATUS status = vDbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, format, list);
      va_end(list);
      return status;
    }
  }
  return STATUS_INVALID_PARAMETER_3;
}